package com.leetcode.algorithm.common;

public class ListNode {
	public int val;
	public ListNode next;

	public ListNode() {
	}

	public ListNode(int val) {
		this.val = val;
	}

	public ListNode(int val, ListNode next) {
		this.val = val;
		this.next = next;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(val);
		ListNode curNode = this.next;
		while (curNode != null) {
			sb.append("->");
			sb.append(curNode.val);
			curNode = curNode.next;
		}
		return sb.toString();
	}
	
	/**
	 * 237. 删除链表中的节点
	 * @param node node != this
	 */
    public void deleteNode(ListNode node) {
		ListNode cur = this;
		ListNode pre = this;
		while (cur.next != null) {
			cur = cur.next;
			if (cur.val == node.val && cur.next == node.next) {
				pre.next = cur.next;
			} else {
				pre = cur;
			}
		}
    }
}